package com.gaff.emp.core.util;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;

import java.util.Map;

public class PageQuery {

    public static <T> IPage<T> getPage(Map<String, Object> params) {
        //分页参数
        long curPage = 1;
        long limit = 10;
        if (params != null) {
            if (params.get("page") != null) {
                curPage = Long.parseLong((String) params.get("page"));
            }
            if (params.get("limit") != null) {
                limit = Long.parseLong((String) params.get("limit"));
            }
        }
        return new Page<>(curPage, limit);
    }

    public static Pageable getElasticPage(Map<String, Object> params) {
        int curPage = 1;
        int limit = 10;
        if (params.get("page") != null) {
            curPage = Integer.parseInt((String) params.get("page"));
        }
        if (params.get("limit") != null) {
            limit = Integer.parseInt((String) params.get("limit"));
        }
        return PageRequest.of(curPage - 1, limit);
    }

}
